/*   1:    */ package tt.dz.web.controller.financial;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import com.alibaba.fastjson.serializer.SerializerFeature;
/*   5:    */ import java.util.ArrayList;
/*   6:    */ import java.util.HashMap;
/*   7:    */ import java.util.Iterator;
/*   8:    */ import java.util.List;
/*   9:    */ import java.util.Map;
/*  10:    */ import java.util.Set;
/*  11:    */ import javax.annotation.Resource;
/*  12:    */ import javax.servlet.http.HttpServletRequest;
/*  13:    */ import javax.servlet.http.HttpServletResponse;
/*  14:    */ import org.apache.commons.collections.CollectionUtils;
/*  15:    */ import org.springframework.stereotype.Controller;
/*  16:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  17:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  18:    */ import tt.dz.biz.service.financial.SubjectService;
/*  19:    */ import tt.dz.common.LogUtil;
/*  20:    */ import tt.dz.vo.ResponseModle;
/*  21:    */ import tt.dz.vo.SubjectVO;
/*  22:    */ 
/*  23:    */ @Controller
/*  24:    */ public class SubjectController
/*  25:    */ {
/*  26:    */   @Resource(name="subjectService")
/*  27:    */   private SubjectService subjectService;
/*  28:    */   
/*  29:    */   @RequestMapping(value={"/queryAccountingRuleSubject"}, produces={"application/json;charset=UTF-8"})
/*  30:    */   @ResponseBody
/*  31:    */   public String queryAccountingRuleSubject()
/*  32:    */   {
/*  33: 34 */     return this.subjectService.getAccountingRuleSubject();
/*  34:    */   }
/*  35:    */   
/*  36:    */   @RequestMapping(value={"/queryAssetsLbltsAccountRuleSubject"}, produces={"application/json;charset=UTF-8"})
/*  37:    */   @ResponseBody
/*  38:    */   public String queryAssetsLbltsAccountRuleSubject()
/*  39:    */   {
/*  40: 39 */     return this.subjectService.getAssetsLbltsAccountRuleSubject();
/*  41:    */   }
/*  42:    */   
/*  43:    */   @RequestMapping(value={"/querySubject"}, produces={"application/json;charset=UTF-8"})
/*  44:    */   @ResponseBody
/*  45:    */   public String querySubject()
/*  46:    */   {
/*  47: 49 */     ResponseModle responseModle = null;
/*  48:    */     try
/*  49:    */     {
/*  50: 51 */       List<SubjectVO> subjectList = this.subjectService.querySubject();
/*  51:    */       
/*  52:    */ 
/*  53:    */ 
/*  54:    */ 
/*  55: 56 */       responseModle = new ResponseModle("success", subjectList);
/*  56:    */     }
/*  57:    */     catch (Exception e)
/*  58:    */     {
/*  59: 58 */       LogUtil.error("查询科目类型异常", e);
/*  60: 59 */       responseModle = new ResponseModle("error", new ArrayList());
/*  61:    */     }
/*  62: 61 */     return JSON.toJSONString(responseModle);
/*  63:    */   }
/*  64:    */   
/*  65:    */   @RequestMapping(value={"/queryChannelSubject"}, produces={"application/json;charset=UTF-8"})
/*  66:    */   @ResponseBody
/*  67:    */   public String queryChannelSubject()
/*  68:    */   {
/*  69: 71 */     ResponseModle responseModle = null;
/*  70:    */     try
/*  71:    */     {
/*  72: 73 */       List<SubjectVO> subjectList = this.subjectService.queryChannelSubject();
/*  73: 74 */       Iterator<SubjectVO> iterator = subjectList.iterator();
/*  74: 75 */       SubjectVO sourceSubject = null;
/*  75: 76 */       Map<String, Object> resultMap = new HashMap();
/*  76: 77 */       while (iterator.hasNext())
/*  77:    */       {
/*  78: 78 */         sourceSubject = (SubjectVO)iterator.next();
/*  79: 79 */         resultMap.put(sourceSubject.getSubjectCode(), sourceSubject);
/*  80:    */       }
/*  81: 81 */       responseModle = new ResponseModle("success", resultMap);
/*  82:    */     }
/*  83:    */     catch (Exception e)
/*  84:    */     {
/*  85: 83 */       LogUtil.error("查询可关联支付渠道的二级科目类型异常", e);
/*  86: 84 */       responseModle = new ResponseModle("error", new ArrayList());
/*  87:    */     }
/*  88: 86 */     return JSON.toJSONString(responseModle);
/*  89:    */   }
/*  90:    */   
/*  91:    */   @RequestMapping(value={"/listAllSubject"}, produces={"application/json;charset=UTF-8"})
/*  92:    */   @ResponseBody
/*  93:    */   public String listAllSubject()
/*  94:    */   {
/*  95: 96 */     ResponseModle responseModle = null;
/*  96:    */     try
/*  97:    */     {
/*  98: 98 */       List<SubjectVO> subjectList = this.subjectService.querySubject();
/*  99: 99 */       SubjectVO subjectVO = new SubjectVO();
/* 100:100 */       subjectVO.setSubjectCode("#");
/* 101:101 */       recursiveSubjcet(subjectVO, subjectList);
/* 102:102 */       Iterator<SubjectVO> iterator = subjectList.iterator();
/* 103:103 */       SubjectVO sourceSubject = null;
/* 104:104 */       Map<String, Object> resultMap = new HashMap();
/* 105:105 */       while (iterator.hasNext())
/* 106:    */       {
/* 107:106 */         sourceSubject = (SubjectVO)iterator.next();
/* 108:107 */         resultMap.put(sourceSubject.getSubjectCode(), sourceSubject);
/* 109:    */       }
/* 110:109 */       responseModle = new ResponseModle("success", resultMap);
/* 111:    */     }
/* 112:    */     catch (Exception e)
/* 113:    */     {
/* 114:111 */       LogUtil.error("查询科目类型异常", e);
/* 115:112 */       responseModle = new ResponseModle("error", new HashMap());
/* 116:    */     }
/* 117:114 */     return JSON.toJSONString(responseModle, new SerializerFeature[] { SerializerFeature.DisableCircularReferenceDetect });
/* 118:    */   }
/* 119:    */   
/* 120:    */   @RequestMapping(value={"/modifySubject"}, produces={"application/json;charset=UTF-8"})
/* 121:    */   @ResponseBody
/* 122:    */   public String modifySubject(HttpServletRequest request, HttpServletResponse response)
/* 123:    */   {
/* 124:126 */     ResponseModle responseModle = new ResponseModle();
/* 125:    */     try
/* 126:    */     {
/* 127:128 */       String modifyType = request.getParameter("modifyType");
/* 128:129 */       SubjectVO subjectVO = (SubjectVO)JSON.parseObject(request.getParameter("subjectVO"), SubjectVO.class);
/* 129:130 */       List<SubjectVO> sameNamesubjectList = this.subjectService.querySubjectByNameAndParentCode(subjectVO);
/* 130:131 */       if (CollectionUtils.isNotEmpty(sameNamesubjectList))
/* 131:    */       {
/* 132:132 */         responseModle.setRequestStatus("error");
/* 133:133 */         responseModle.setRequestResult("存在同名科目，请修改科目名称。");
/* 134:134 */         return JSON.toJSONString(responseModle);
/* 135:    */       }
/* 136:136 */       if ("insert".equals(modifyType))
/* 137:    */       {
/* 138:137 */         this.subjectService.insertSubject(subjectVO);
/* 139:138 */         responseModle.setRequestStatus("success");
/* 140:    */       }
/* 141:139 */       else if ("update".equals(modifyType))
/* 142:    */       {
/* 143:140 */         if (this.subjectService.updateSubject(subjectVO))
/* 144:    */         {
/* 145:141 */           responseModle.setRequestStatus("success");
/* 146:    */         }
/* 147:    */         else
/* 148:    */         {
/* 149:143 */           responseModle.setRequestStatus("error");
/* 150:144 */           responseModle.setRequestResult("更新失败，请稍后再试。");
/* 151:    */         }
/* 152:    */       }
/* 153:    */     }
/* 154:    */     catch (Exception e)
/* 155:    */     {
/* 156:148 */       LogUtil.error("更改科目类型异常", e);
/* 157:149 */       responseModle.setRequestStatus("error");
/* 158:150 */       responseModle.setRequestResult("系统异常，请稍后再试。");
/* 159:    */     }
/* 160:152 */     return JSON.toJSONString(responseModle);
/* 161:    */   }
/* 162:    */   
/* 163:    */   public void getChildrenSubject(SubjectVO subjectVO, List<SubjectVO> subjectList)
/* 164:    */   {
/* 165:156 */     Iterator<SubjectVO> iterator = subjectList.iterator();
/* 166:157 */     SubjectVO sourceSubject = null;
/* 167:158 */     while (iterator.hasNext())
/* 168:    */     {
/* 169:159 */       sourceSubject = (SubjectVO)iterator.next();
/* 170:160 */       if (sourceSubject.getParentSubjectCode().equals(subjectVO.getSubjectCode())) {
/* 171:161 */         subjectVO.getChildrenSubject().add(sourceSubject);
/* 172:    */       }
/* 173:    */     }
/* 174:    */   }
/* 175:    */   
/* 176:    */   public void recursiveSubjcet(SubjectVO subjectVO, List<SubjectVO> subjectList)
/* 177:    */   {
/* 178:167 */     getChildrenSubject(subjectVO, subjectList);
/* 179:168 */     if (subjectVO.getChildrenSubject().size() > 0)
/* 180:    */     {
/* 181:169 */       Iterator<SubjectVO> iterator = subjectVO.getChildrenSubject().iterator();
/* 182:170 */       SubjectVO sourceSubject = null;
/* 183:171 */       while (iterator.hasNext())
/* 184:    */       {
/* 185:172 */         sourceSubject = (SubjectVO)iterator.next();
/* 186:173 */         recursiveSubjcet(sourceSubject, subjectList);
/* 187:    */       }
/* 188:    */     }
/* 189:    */   }
/* 190:    */   
/* 191:    */   public void removeChildren(List<SubjectVO> subjectList)
/* 192:    */   {
/* 193:179 */     Iterator<SubjectVO> iterator = subjectList.iterator();
/* 194:180 */     while (iterator.hasNext()) {
/* 195:181 */       if (!"#".equals(((SubjectVO)iterator.next()).getParentSubjectCode())) {
/* 196:182 */         iterator.remove();
/* 197:    */       }
/* 198:    */     }
/* 199:    */   }
/* 200:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.financial.SubjectController
 * JD-Core Version:    0.7.0.1
 */